<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>GeoDjango Installation &mdash; Django 1.7.8.dev20150401230226 documentation</title>
    
    <link rel="stylesheet" href="../../../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../../../',
        VERSION:     '1.7.8.dev20150401230226',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../../../_static/doctools.js"></script>
    <link rel="top" title="Django 1.7.8.dev20150401230226 documentation" href="../../../../index.html" />
    <link rel="up" title="GeoDjango" href="../index.html" />
    <link rel="next" title="Installing Geospatial libraries" href="geolibs.html" />
    <link rel="prev" title="GeoDjango Tutorial" href="../tutorial.html" />



 
<script type="text/javascript" src="../../../../templatebuiltins.js"></script>
<script type="text/javascript">
(function($) {
    if (!django_template_builtins) {
       // templatebuiltins.js missing, do nothing.
       return;
    }
    $(document).ready(function() {
        // Hyperlink Django template tags and filters
        var base = "../../../templates/builtins.html";
        if (base == "#") {
            // Special case for builtins.html itself
            base = "";
        }
        // Tags are keywords, class '.k'
        $("div.highlight\\-html\\+django span.k").each(function(i, elem) {
             var tagname = $(elem).text();
             if ($.inArray(tagname, django_template_builtins.ttags) != -1) {
                 var fragment = tagname.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>");
             }
        });
        // Filters are functions, class '.nf'
        $("div.highlight\\-html\\+django span.nf").each(function(i, elem) {
             var filtername = $(elem).text();
             if ($.inArray(filtername, django_template_builtins.tfilters) != -1) {
                 var fragment = filtername.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>");
             }
        });
    });
})(jQuery);
</script>


  </head>
  <body>

    <div class="document">
  <div id="custom-doc" class="yui-t6">
    <div id="hd">
      <h1><a href="../../../../index.html">Django 1.7.8.dev20150401230226 documentation</a></h1>
      <div id="global-nav">
        <a title="Home page" href="../../../../index.html">Home</a>  |
        <a title="Table of contents" href="../../../../contents.html">Table of contents</a>  |
        <a title="Global index" href="../../../../genindex.html">Index</a>  |
        <a title="Module index" href="../../../../py-modindex.html">Modules</a>
      </div>
      <div class="nav">
    &laquo; <a href="../tutorial.html" title="GeoDjango Tutorial">previous</a>
     |
    <a href="../../../index.html" title="API Reference" accesskey="U">up</a>
   |
    <a href="geolibs.html" title="Installing Geospatial libraries">next</a> &raquo;</div>
    </div>

    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="ref-contrib-gis-install-index">
            
  <div class="section" id="s-geodjango-installation">
<span id="s-ref-gis-install"></span><span id="geodjango-installation"></span><span id="ref-gis-install"></span><h1>GeoDjango Installation<a class="headerlink" href="#geodjango-installation" title="Permalink to this headline">¶</a></h1>
<div class="section" id="s-overview">
<span id="overview"></span><h2>Overview<a class="headerlink" href="#overview" title="Permalink to this headline">¶</a></h2>
<p>In general, GeoDjango installation requires:</p>
<ol class="arabic simple">
<li><a class="reference internal" href="#django"><em>Python and Django</em></a></li>
<li><a class="reference internal" href="#spatial-database"><em>Spatial database</em></a></li>
<li><a class="reference internal" href="geolibs.html#geospatial-libs"><em>Installing Geospatial libraries</em></a></li>
</ol>
<p>Details for each of the requirements and installation instructions
are provided in the sections below. In addition, platform-specific
instructions are available for:</p>
<ul class="simple">
<li><a class="reference internal" href="#macosx"><em>Mac OS X</em></a></li>
<li><a class="reference internal" href="#windows"><em>Windows</em></a></li>
</ul>
<div class="admonition-use-the-source admonition">
<p class="first admonition-title">Use the Source</p>
<p class="last">Because GeoDjango takes advantage of the latest in the open source geospatial
software technology, recent versions of the libraries are necessary.
If binary packages aren&#8217;t available for your platform, installation from
source may be required. When compiling the libraries from source, please
follow the directions closely, especially if you&#8217;re a beginner.</p>
</div>
</div>
<div class="section" id="s-requirements">
<span id="requirements"></span><h2>Requirements<a class="headerlink" href="#requirements" title="Permalink to this headline">¶</a></h2>
<div class="section" id="s-python-and-django">
<span id="s-django"></span><span id="python-and-django"></span><span id="django"></span><h3>Python and Django<a class="headerlink" href="#python-and-django" title="Permalink to this headline">¶</a></h3>
<p>Because GeoDjango is included with Django, please refer to Django&#8217;s
<a class="reference internal" href="../../../../topics/install.html#installing-official-release"><em>installation instructions</em></a> for details on
how to install.</p>
</div>
<div class="section" id="s-spatial-database">
<span id="s-id1"></span><span id="spatial-database"></span><span id="id1"></span><h3>Spatial database<a class="headerlink" href="#spatial-database" title="Permalink to this headline">¶</a></h3>
<p>PostgreSQL (with PostGIS), MySQL (mostly with MyISAM engine), Oracle, and SQLite
(with SpatiaLite) are the spatial databases currently supported.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">PostGIS is recommended, because it is the most mature and feature-rich
open source spatial database.</p>
</div>
<p>The geospatial libraries required for a GeoDjango installation depends
on the spatial database used.  The following lists the library requirements,
supported versions, and any notes for each of the supported database backends:</p>
<table class="docutils">
<colgroup>
<col width="13%" />
<col width="21%" />
<col width="13%" />
<col width="54%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Database</th>
<th class="head">Library Requirements</th>
<th class="head">Supported Versions</th>
<th class="head">Notes</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>PostgreSQL</td>
<td>GEOS, PROJ.4, PostGIS</td>
<td>8.4+</td>
<td>Requires PostGIS.</td>
</tr>
<tr class="row-odd"><td>MySQL</td>
<td>GEOS</td>
<td>5.x</td>
<td>Not OGC-compliant; <a class="reference internal" href="../db-api.html#mysql-spatial-limitations"><em>limited functionality</em></a>.</td>
</tr>
<tr class="row-even"><td>Oracle</td>
<td>GEOS</td>
<td>10.2, 11</td>
<td>XE not supported; not tested with 9.</td>
</tr>
<tr class="row-odd"><td>SQLite</td>
<td>GEOS, GDAL, PROJ.4, SpatiaLite</td>
<td>3.6.+</td>
<td>Requires SpatiaLite 2.3+, pysqlite2 2.5+</td>
</tr>
</tbody>
</table>
<p>See also <a class="reference external" href="http://trac.osgeo.org/postgis/wiki/UsersWikiPostgreSQLPostGIS">this comparison matrix</a> on the OSGeo Wiki for
PostgreSQL/PostGIS/GEOS/GDAL possible combinations.</p>
</div>
</div>
<div class="section" id="s-installation">
<span id="installation"></span><h2>Installation<a class="headerlink" href="#installation" title="Permalink to this headline">¶</a></h2>
<div class="section" id="s-geospatial-libraries">
<span id="geospatial-libraries"></span><h3>Geospatial libraries<a class="headerlink" href="#geospatial-libraries" title="Permalink to this headline">¶</a></h3>
<div class="toctree-wrapper compound">
<ul>
<li class="toctree-l1"><a class="reference internal" href="geolibs.html">Installing Geospatial libraries</a></li>
</ul>
</div>
</div>
<div class="section" id="s-database-installation">
<span id="database-installation"></span><h3>Database installation<a class="headerlink" href="#database-installation" title="Permalink to this headline">¶</a></h3>
<div class="toctree-wrapper compound">
<ul>
<li class="toctree-l1"><a class="reference internal" href="postgis.html">Installing PostGIS</a></li>
<li class="toctree-l1"><a class="reference internal" href="spatialite.html">Installing Spatialite</a></li>
</ul>
</div>
</div>
<div class="section" id="s-add-django-contrib-gis-to-installed-apps">
<span id="add-django-contrib-gis-to-installed-apps"></span><h3>Add <tt class="docutils literal"><span class="pre">django.contrib.gis</span></tt> to <a class="reference internal" href="../../../settings.html#std:setting-INSTALLED_APPS"><tt class="xref std std-setting docutils literal"><span class="pre">INSTALLED_APPS</span></tt></a><a class="headerlink" href="#add-django-contrib-gis-to-installed-apps" title="Permalink to this headline">¶</a></h3>
<p>Like other Django contrib applications, you will <em>only</em> need to add
<a class="reference internal" href="../index.html#module-django.contrib.gis" title="django.contrib.gis: Geographic Information System (GIS) extensions for Django"><tt class="xref py py-mod docutils literal"><span class="pre">django.contrib.gis</span></tt></a> to <a class="reference internal" href="../../../settings.html#std:setting-INSTALLED_APPS"><tt class="xref std std-setting docutils literal"><span class="pre">INSTALLED_APPS</span></tt></a> in your settings.
This is the so that <tt class="docutils literal"><span class="pre">gis</span></tt> templates can be located &#8211; if not done, then
features such as the geographic admin or KML sitemaps will not function properly.</p>
</div>
<div class="section" id="s-add-google-projection-to-spatial-ref-sys-table">
<span id="s-addgoogleprojection"></span><span id="add-google-projection-to-spatial-ref-sys-table"></span><span id="addgoogleprojection"></span><h3>Add Google projection to <tt class="docutils literal"><span class="pre">spatial_ref_sys</span></tt> table<a class="headerlink" href="#add-google-projection-to-spatial-ref-sys-table" title="Permalink to this headline">¶</a></h3>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">If you&#8217;re running PostGIS 1.4 or above, you can skip this step. The entry
is already included in the default <tt class="docutils literal"><span class="pre">spatial_ref_sys</span></tt> table.</p>
</div>
<p>In order to conduct database transformations to the so-called &#8220;Google&#8221;
projection (a spherical mercator projection used by Google Maps),
an entry must be added to your spatial database&#8217;s <tt class="docutils literal"><span class="pre">spatial_ref_sys</span></tt> table.
Invoke the Django shell from your project and execute the
<tt class="docutils literal"><span class="pre">add_srs_entry</span></tt> function:</p>
<div class="highlight-pycon"><div class="highlight"><pre><span class="go">$ python manage.py shell</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">django.contrib.gis.utils</span> <span class="kn">import</span> <span class="n">add_srs_entry</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">add_srs_entry</span><span class="p">(</span><span class="mi">900913</span><span class="p">)</span>
</pre></div>
</div>
<p>This adds an entry for the 900913 SRID to the <tt class="docutils literal"><span class="pre">spatial_ref_sys</span></tt> (or equivalent)
table, making it possible for the spatial database to transform coordinates in
this projection.  You only need to execute this command <em>once</em> per spatial database.</p>
</div>
</div>
<div class="section" id="s-troubleshooting">
<span id="troubleshooting"></span><h2>Troubleshooting<a class="headerlink" href="#troubleshooting" title="Permalink to this headline">¶</a></h2>
<p>If you can&#8217;t find the solution to your problem here then participate in the
community!  You can:</p>
<ul class="simple">
<li>Join the <tt class="docutils literal"><span class="pre">#geodjango</span></tt> IRC channel on Freenode. Please be patient and polite
&#8211; while you may not get an immediate response, someone will attempt to answer
your question as soon as they see it.</li>
<li>Ask your question on the <a class="reference external" href="https://groups.google.com/d/forum/geodjango">GeoDjango</a> mailing list.</li>
<li>File a ticket on the <a class="reference external" href="https://code.djangoproject.com/newticket">Django trac</a> if you think there&#8217;s a bug.  Make
sure to provide a complete description of the problem, versions used,
and specify the component as &#8220;GIS&#8221;.</li>
</ul>
<div class="section" id="s-library-environment-settings">
<span id="s-libsettings"></span><span id="library-environment-settings"></span><span id="libsettings"></span><h3>Library environment settings<a class="headerlink" href="#library-environment-settings" title="Permalink to this headline">¶</a></h3>
<p>By far, the most common problem when installing GeoDjango is that the
external shared libraries (e.g., for GEOS and GDAL) cannot be located. <a class="footnote-reference" href="#id28" id="id5">[1]</a>
Typically, the cause of this problem is that the operating system isn&#8217;t aware
of the directory where the libraries built from source were installed.</p>
<p>In general, the library path may be set on a per-user basis by setting
an environment variable, or by configuring the library path for the entire
system.</p>
<div class="section" id="s-ld-library-path-environment-variable">
<span id="ld-library-path-environment-variable"></span><h4><tt class="docutils literal"><span class="pre">LD_LIBRARY_PATH</span></tt> environment variable<a class="headerlink" href="#ld-library-path-environment-variable" title="Permalink to this headline">¶</a></h4>
<p>A user may set this environment variable to customize the library paths
they want to use.  The typical library directory for software
built from source is <tt class="docutils literal"><span class="pre">/usr/local/lib</span></tt>.  Thus, <tt class="docutils literal"><span class="pre">/usr/local/lib</span></tt> needs
to be included in the <tt class="docutils literal"><span class="pre">LD_LIBRARY_PATH</span></tt> variable.  For example, the user
could place the following in their bash profile:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="go">export LD_LIBRARY_PATH=/usr/local/lib</span>
</pre></div>
</div>
</div>
<div class="section" id="s-setting-system-library-path">
<span id="setting-system-library-path"></span><h4>Setting system library path<a class="headerlink" href="#setting-system-library-path" title="Permalink to this headline">¶</a></h4>
<p>On GNU/Linux systems, there is typically a file in <tt class="docutils literal"><span class="pre">/etc/ld.so.conf</span></tt>, which may include
additional paths from files in another directory, such as <tt class="docutils literal"><span class="pre">/etc/ld.so.conf.d</span></tt>.
As the root user, add the custom library path (like <tt class="docutils literal"><span class="pre">/usr/local/lib</span></tt>) on a
new line in <tt class="docutils literal"><span class="pre">ld.so.conf</span></tt>.  This is <em>one</em> example of how to do so:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">$</span> sudo <span class="nb">echo</span> /usr/local/lib &gt;&gt; /etc/ld.so.conf
<span class="gp">$</span> sudo ldconfig
</pre></div>
</div>
<p>For OpenSolaris users, the system library path may be modified using the
<tt class="docutils literal"><span class="pre">crle</span></tt> utility.  Run <tt class="docutils literal"><span class="pre">crle</span></tt> with no options to see the current configuration
and use <tt class="docutils literal"><span class="pre">crle</span> <span class="pre">-l</span></tt> to set with the new library path.  Be <em>very</em> careful when
modifying the system library path:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">#</span> crle -l <span class="nv">$OLD_PATH</span>:/usr/local/lib
</pre></div>
</div>
</div>
<div class="section" id="s-install-binutils">
<span id="s-binutils"></span><span id="install-binutils"></span><span id="binutils"></span><h4>Install <tt class="docutils literal"><span class="pre">binutils</span></tt><a class="headerlink" href="#install-binutils" title="Permalink to this headline">¶</a></h4>
<p>GeoDjango uses the <tt class="docutils literal"><span class="pre">find_library</span></tt> function (from the <tt class="docutils literal"><span class="pre">ctypes.util</span></tt> Python
module) to discover libraries.  The <tt class="docutils literal"><span class="pre">find_library</span></tt> routine uses a program
called <tt class="docutils literal"><span class="pre">objdump</span></tt> (part of the <tt class="docutils literal"><span class="pre">binutils</span></tt> package) to verify a shared
library on GNU/Linux systems.  Thus, if <tt class="docutils literal"><span class="pre">binutils</span></tt> is not installed on your
Linux system then Python&#8217;s ctypes may not be able to find your library even if
your library path is set correctly and geospatial libraries were built perfectly.</p>
<p>The <tt class="docutils literal"><span class="pre">binutils</span></tt> package may be installed on Debian and Ubuntu systems using the
following command:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">$</span> sudo apt-get install binutils
</pre></div>
</div>
<p>Similarly, on Red Hat and CentOS systems:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">$</span> sudo yum install binutils
</pre></div>
</div>
</div>
</div>
</div>
<div class="section" id="s-platform-specific-instructions">
<span id="platform-specific-instructions"></span><h2>Platform-specific instructions<a class="headerlink" href="#platform-specific-instructions" title="Permalink to this headline">¶</a></h2>
<div class="section" id="s-mac-os-x">
<span id="s-macosx"></span><span id="mac-os-x"></span><span id="macosx"></span><h3>Mac OS X<a class="headerlink" href="#mac-os-x" title="Permalink to this headline">¶</a></h3>
<p>Because of the variety of packaging systems available for OS X, users have
several different options for installing GeoDjango. These options are:</p>
<ul class="simple">
<li><a class="reference internal" href="#homebrew"><em>Homebrew</em></a></li>
<li><a class="reference internal" href="#kyngchaos"><em>KyngChaos packages</em></a></li>
<li><a class="reference internal" href="#fink"><em>Fink</em></a></li>
<li><a class="reference internal" href="#macports"><em>MacPorts</em></a></li>
<li><a class="reference internal" href="geolibs.html#build-from-source"><em>Building from source</em></a></li>
</ul>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Currently, the easiest and recommended approach for installing GeoDjango
on OS X is to use the KyngChaos packages.</p>
</div>
<p>This section also includes instructions for installing an upgraded version
of <a class="reference internal" href="#macosx-python"><em>Python</em></a> from packages provided by the Python Software
Foundation, however, this is not required.</p>
<div class="section" id="s-python">
<span id="s-macosx-python"></span><span id="python"></span><span id="macosx-python"></span><h4>Python<a class="headerlink" href="#python" title="Permalink to this headline">¶</a></h4>
<p>Although OS X comes with Python installed, users can use framework
installers (<a class="reference external" href="http://python.org/ftp/python/2.7.5/">2.7</a>, <a class="reference external" href="http://python.org/ftp/python/3.2.5/">3.2</a> and <a class="reference external" href="http://python.org/ftp/python/3.3.2/">3.3</a> are available) provided by
the Python Software Foundation.  An advantage to using the installer is
that OS X&#8217;s Python will remain &#8220;pristine&#8221; for internal operating system
use.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>You will need to modify the <tt class="docutils literal"><span class="pre">PATH</span></tt> environment variable in your
<tt class="docutils literal"><span class="pre">.profile</span></tt> file so that the new version of Python is used when
<tt class="docutils literal"><span class="pre">python</span></tt> is entered at the command-line:</p>
<div class="last highlight-console"><div class="highlight"><pre><span class="go">export PATH=/Library/Frameworks/Python.framework/Versions/Current/bin:$PATH</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="s-homebrew">
<span id="s-id9"></span><span id="homebrew"></span><span id="id9"></span><h4>Homebrew<a class="headerlink" href="#homebrew" title="Permalink to this headline">¶</a></h4>
<p><a class="reference external" href="http://brew.sh/">Homebrew</a> provides &#8220;recipes&#8221; for building binaries and packages from source.
It provides recipes for the GeoDjango prerequisites on Macintosh computers
running OS X. Because Homebrew still builds the software from source, the
<a class="reference external" href="https://developer.apple.com/technologies/tools/">Apple Developer Tools</a> are required.</p>
<p>Summary:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">$</span> brew install postgresql
<span class="gp">$</span> brew install postgis
<span class="gp">$</span> brew install gdal
<span class="gp">$</span> brew install libgeoip
</pre></div>
</div>
</div>
<div class="section" id="s-kyngchaos-packages">
<span id="s-kyngchaos"></span><span id="kyngchaos-packages"></span><span id="kyngchaos"></span><h4>KyngChaos packages<a class="headerlink" href="#kyngchaos-packages" title="Permalink to this headline">¶</a></h4>
<p>William Kyngesburye provides a number of <a class="reference external" href="http://www.kyngchaos.com/software/frameworks">geospatial library binary packages</a>
that make it simple to get GeoDjango installed on OS X without compiling
them from source.  However, the <a class="reference external" href="https://developer.apple.com/technologies/tools/">Apple Developer Tools</a> are still necessary
for compiling the Python database adapters <a class="reference internal" href="#psycopg2-kyngchaos"><em>psycopg2</em></a> (for PostGIS)
and <a class="reference internal" href="spatialite.html#pysqlite2"><em>pysqlite2</em></a> (for SpatiaLite).</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">SpatiaLite users should consult the <a class="reference internal" href="spatialite.html#spatialite-macosx"><em>Mac OS X-specific instructions</em></a> section
after installing the packages for additional instructions.</p>
</div>
<p>Download the framework packages for:</p>
<ul class="simple">
<li>UnixImageIO</li>
<li>PROJ</li>
<li>GEOS</li>
<li>SQLite3 (includes the SpatiaLite library)</li>
<li>GDAL</li>
</ul>
<p>Install the packages in the order they are listed above, as the GDAL and SQLite
packages require the packages listed before them.</p>
<p>Afterwards, you can also install the KyngChaos binary packages for <a class="reference external" href="http://www.kyngchaos.com/software/postgres">PostgreSQL
and PostGIS</a>.</p>
<p>After installing the binary packages, you&#8217;ll want to add the following to
your <tt class="docutils literal"><span class="pre">.profile</span></tt> to be able to run the package programs from the command-line:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="go">export PATH=/Library/Frameworks/UnixImageIO.framework/Programs:$PATH</span>
<span class="go">export PATH=/Library/Frameworks/PROJ.framework/Programs:$PATH</span>
<span class="go">export PATH=/Library/Frameworks/GEOS.framework/Programs:$PATH</span>
<span class="go">export PATH=/Library/Frameworks/SQLite3.framework/Programs:$PATH</span>
<span class="go">export PATH=/Library/Frameworks/GDAL.framework/Programs:$PATH</span>
<span class="go">export PATH=/usr/local/pgsql/bin:$PATH</span>
</pre></div>
</div>
<div class="section" id="s-psycopg2">
<span id="s-psycopg2-kyngchaos"></span><span id="psycopg2"></span><span id="psycopg2-kyngchaos"></span><h5>psycopg2<a class="headerlink" href="#psycopg2" title="Permalink to this headline">¶</a></h5>
<p>After you&#8217;ve installed the KyngChaos binaries and modified your <tt class="docutils literal"><span class="pre">PATH</span></tt>, as
described above, <tt class="docutils literal"><span class="pre">psycopg2</span></tt> may be installed using the following command:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">$</span> sudo pip install psycopg2
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">If you don&#8217;t have <tt class="docutils literal"><span class="pre">pip</span></tt>, follow the <a class="reference internal" href="../../../../topics/install.html#installing-official-release"><em>installation instructions</em></a> to install it.</p>
</div>
</div>
</div>
<div class="section" id="s-fink">
<span id="s-id13"></span><span id="fink"></span><span id="id13"></span><h4>Fink<a class="headerlink" href="#fink" title="Permalink to this headline">¶</a></h4>
<p><a class="reference external" href="http://schwehr.org/blog/">Kurt Schwehr</a> has been gracious enough to create GeoDjango packages for users
of the <a class="reference external" href="http://www.finkproject.org/">Fink</a> package system. <a class="reference external" href="http://pdb.finkproject.org/pdb/browse.php?summary=django-gis">Different packages are available</a> (starting
with &#8220;django-gis&#8221;), depending on which version of Python you want to use.</p>
</div>
<div class="section" id="s-macports">
<span id="s-id17"></span><span id="macports"></span><span id="id17"></span><h4>MacPorts<a class="headerlink" href="#macports" title="Permalink to this headline">¶</a></h4>
<p><a class="reference external" href="http://www.macports.org/">MacPorts</a> may be used to install GeoDjango prerequisites on Macintosh
computers running OS X.  Because MacPorts still builds the software from source,
the <a class="reference external" href="https://developer.apple.com/technologies/tools/">Apple Developer Tools</a> are required.</p>
<p>Summary:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="gp">$</span> sudo port install postgresql83-server
<span class="gp">$</span> sudo port install geos
<span class="gp">$</span> sudo port install proj
<span class="gp">$</span> sudo port install postgis
<span class="gp">$</span> sudo port install gdal +geos
<span class="gp">$</span> sudo port install libgeoip
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>You will also have to modify the <tt class="docutils literal"><span class="pre">PATH</span></tt> in your <tt class="docutils literal"><span class="pre">.profile</span></tt> so
that the MacPorts programs are accessible from the command-line:</p>
<div class="highlight-console"><div class="highlight"><pre><span class="go">export PATH=/opt/local/bin:/opt/local/lib/postgresql83/bin</span>
</pre></div>
</div>
<p>In addition, add the <tt class="docutils literal"><span class="pre">DYLD_FALLBACK_LIBRARY_PATH</span></tt> setting so that
the libraries can be found by Python:</p>
<div class="last highlight-console"><div class="highlight"><pre><span class="go">export DYLD_FALLBACK_LIBRARY_PATH=/opt/local/lib:/opt/local/lib/postgresql83</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="section" id="s-windows">
<span id="s-id19"></span><span id="windows"></span><span id="id19"></span><h3>Windows<a class="headerlink" href="#windows" title="Permalink to this headline">¶</a></h3>
<p>Proceed through the following sections sequentially in order to install
GeoDjango on Windows.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">These instructions assume that you are using 32-bit versions of
all programs.  While 64-bit versions of Python and PostgreSQL 9.x
are available, 64-bit versions of spatial libraries, like
GEOS and GDAL, are not yet provided by the <a class="reference internal" href="#osgeo4w"><em>OSGeo4W</em></a> installer.</p>
</div>
<div class="section" id="s-id20">
<span id="id20"></span><h4>Python<a class="headerlink" href="#id20" title="Permalink to this headline">¶</a></h4>
<p>First, download the latest <a class="reference external" href="http://python.org/download/">Python 2.7 installer</a> from the Python Web site.
Next, run the installer and keep the defaults &#8211; for example, keep
&#8216;Install for all users&#8217; checked and the installation path set as
<tt class="docutils literal"><span class="pre">C:\Python27</span></tt>.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">You may already have a version of Python installed in <tt class="docutils literal"><span class="pre">C:\python</span></tt> as ESRI
products sometimes install a copy there.  <em>You should still install a
fresh version of Python 2.7.</em></p>
</div>
</div>
<div class="section" id="s-postgresql">
<span id="postgresql"></span><h4>PostgreSQL<a class="headerlink" href="#postgresql" title="Permalink to this headline">¶</a></h4>
<p>First, download the latest <a class="reference external" href="http://www.enterprisedb.com/products-services-training/pgdownload">PostgreSQL 9.x installer</a> from the
<a class="reference external" href="http://www.enterprisedb.com">EnterpriseDB</a> Web site.  After downloading, simply run the installer,
follow the on-screen directions, and keep the default options unless
you know the consequences of changing them.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">The PostgreSQL installer creates both a new Windows user to be the
&#8216;postgres service account&#8217; and a <tt class="docutils literal"><span class="pre">postgres</span></tt> database superuser
You will be prompted once to set the password for both accounts &#8211;
make sure to remember it!</p>
</div>
<p>When the installer completes, it will ask to launch the Application Stack
Builder (ASB) on exit &#8211; keep this checked, as it is necessary to
install <a class="reference internal" href="#postgisasb"><em>PostGIS</em></a>.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">If installed successfully, the PostgreSQL server will run in the
background each time the system as started as a Windows service.
A <em class="menuselection">PostgreSQL 9.x</em> start menu group will created
and contains shortcuts for the ASB as well as the &#8216;SQL Shell&#8217;,
which will launch a <tt class="docutils literal"><span class="pre">psql</span></tt> command window.</p>
</div>
</div>
<div class="section" id="s-postgis">
<span id="s-postgisasb"></span><span id="postgis"></span><span id="postgisasb"></span><h4>PostGIS<a class="headerlink" href="#postgis" title="Permalink to this headline">¶</a></h4>
<p>From within the Application Stack Builder (to run outside of the installer,
<em class="menuselection">Start ‣ Programs ‣ PostgreSQL 9.x</em>), select
<em class="menuselection">PostgreSQL Database Server 9.x on port 5432</em> from the drop down
menu.  Next, expand the <em class="menuselection">Categories ‣ Spatial Extensions</em> menu
tree and select <em class="menuselection">PostGIS 1.5 for PostgreSQL 9.x</em>.</p>
<p>After clicking next, you will be prompted to select your mirror, PostGIS
will be downloaded, and the PostGIS installer will begin.  Select only the
default options during install (e.g., do not uncheck the option to create a
default PostGIS database).</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">You will be prompted to enter your <tt class="docutils literal"><span class="pre">postgres</span></tt> database superuser
password in the &#8216;Database Connection Information&#8217; dialog.</p>
</div>
</div>
<div class="section" id="s-id24">
<span id="id24"></span><h4>psycopg2<a class="headerlink" href="#id24" title="Permalink to this headline">¶</a></h4>
<p>The <tt class="docutils literal"><span class="pre">psycopg2</span></tt> Python module provides the interface between Python and the
PostgreSQL database.  Download the latest <a class="reference external" href="http://www.stickpeople.com/projects/python/win-psycopg/">Windows installer</a> for your version
of Python and PostgreSQL and run using the default settings. <a class="footnote-reference" href="#id29" id="id25">[2]</a></p>
</div>
<div class="section" id="s-osgeo4w">
<span id="s-id27"></span><span id="osgeo4w"></span><span id="id27"></span><h4>OSGeo4W<a class="headerlink" href="#osgeo4w" title="Permalink to this headline">¶</a></h4>
<p>The <a class="reference external" href="http://trac.osgeo.org/osgeo4w/">OSGeo4W installer</a> makes it simple to install the PROJ.4, GDAL, and GEOS
libraries required by GeoDjango.  First, download the <a class="reference external" href="http://trac.osgeo.org/osgeo4w/">OSGeo4W installer</a>,
and run it.  Select <em class="menuselection">Express Web-GIS Install</em> and click next.
In the &#8216;Select Packages&#8217; list, ensure that GDAL is selected; MapServer and
Apache are also enabled by default, but are not required by GeoDjango and
may be unchecked safely.  After clicking next, the packages will be
automatically downloaded and installed, after which you may exit the
installer.</p>
</div>
<div class="section" id="s-modify-windows-environment">
<span id="modify-windows-environment"></span><h4>Modify Windows environment<a class="headerlink" href="#modify-windows-environment" title="Permalink to this headline">¶</a></h4>
<p>In order to use GeoDjango, you will need to add your Python and OSGeo4W
directories to your Windows system <tt class="docutils literal"><span class="pre">Path</span></tt>, as well as create <tt class="docutils literal"><span class="pre">GDAL_DATA</span></tt>
and <tt class="docutils literal"><span class="pre">PROJ_LIB</span></tt> environment variables.  The following set of commands,
executable with <tt class="docutils literal"><span class="pre">cmd.exe</span></tt>, will set this up:</p>
<div class="highlight-bat"><div class="highlight"><pre><span class="k">set</span> <span class="nv">OSGEO4W_ROOT</span><span class="o">=</span>C:\OSGeo<span class="m">4</span>W
<span class="k">set</span> <span class="nv">PYTHON_ROOT</span><span class="o">=</span>C:\Python<span class="m">27</span>
<span class="k">set</span> <span class="nv">GDAL_DATA</span><span class="o">=</span><span class="nv">%OSGEO4W_ROOT%</span>\share\gdal
<span class="k">set</span> <span class="nv">PROJ_LIB</span><span class="o">=</span><span class="nv">%OSGEO4W_ROOT%</span>\share\proj
<span class="k">set</span> <span class="nv">PATH</span><span class="o">=</span><span class="nv">%PATH%</span>;<span class="nv">%PYTHON_ROOT%</span>;<span class="nv">%OSGEO4W_ROOT%</span>\bin
reg ADD <span class="s2">&quot;HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment&quot;</span> <span class="n">/v</span> Path <span class="n">/t</span> REG_EXPAND_SZ <span class="n">/f</span> <span class="n">/d</span> <span class="s2">&quot;%PATH%&quot;</span>
reg ADD <span class="s2">&quot;HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment&quot;</span> <span class="n">/v</span> GDAL_DATA <span class="n">/t</span> REG_EXPAND_SZ <span class="n">/f</span> <span class="n">/d</span> <span class="s2">&quot;%GDAL_DATA%&quot;</span>
reg ADD <span class="s2">&quot;HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment&quot;</span> <span class="n">/v</span> PROJ_LIB <span class="n">/t</span> REG_EXPAND_SZ <span class="n">/f</span> <span class="n">/d</span> <span class="s2">&quot;%PROJ_LIB%&quot;</span>
</pre></div>
</div>
<p>For your convenience, these commands are available in the executable batch
script, <a class="reference download internal" href="../../../../_downloads/geodjango_setup.bat"><tt class="xref download docutils literal"><span class="pre">geodjango_setup.bat</span></tt></a>.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Administrator privileges are required to execute these commands.
To do this, right-click on <a class="reference download internal" href="../../../../_downloads/geodjango_setup.bat"><tt class="xref download docutils literal"><span class="pre">geodjango_setup.bat</span></tt></a> and select
<em class="menuselection">Run as administrator</em>. You need to log out and log back in again
for the settings to take effect.</p>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">If you customized the Python or OSGeo4W installation directories,
then you will need to modify the <tt class="docutils literal"><span class="pre">OSGEO4W_ROOT</span></tt> and/or <tt class="docutils literal"><span class="pre">PYTHON_ROOT</span></tt>
variables accordingly.</p>
</div>
</div>
<div class="section" id="s-install-django-and-set-up-database">
<span id="install-django-and-set-up-database"></span><h4>Install Django and set up database<a class="headerlink" href="#install-django-and-set-up-database" title="Permalink to this headline">¶</a></h4>
<p>Finally, <a class="reference internal" href="../../../../topics/install.html#installing-official-release"><em>install Django</em></a> on your system.</p>
<p class="rubric">Footnotes</p>
<table class="docutils footnote" frame="void" id="id28" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id5">[1]</a></td><td>GeoDjango uses the <a class="reference external" href="http://docs.python.org/3/library/ctypes.html#ctypes.util.find_library" title="(in Python v3.4)"><tt class="xref py py-func docutils literal"><span class="pre">find_library()</span></tt></a> routine from
<tt class="docutils literal"><span class="pre">ctypes.util</span></tt> to locate shared libraries.</td></tr>
</tbody>
</table>
<table class="docutils footnote" frame="void" id="id29" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id25">[2]</a></td><td>The <tt class="docutils literal"><span class="pre">psycopg2</span></tt> Windows installers are packaged and maintained by
<a class="reference external" href="http://www.stickpeople.com/projects/python/win-psycopg/">Jason Erickson</a>.</td></tr>
</tbody>
</table>
</div>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../../../../contents.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">GeoDjango Installation</a><ul>
<li><a class="reference internal" href="#overview">Overview</a></li>
<li><a class="reference internal" href="#requirements">Requirements</a><ul>
<li><a class="reference internal" href="#python-and-django">Python and Django</a></li>
<li><a class="reference internal" href="#spatial-database">Spatial database</a></li>
</ul>
</li>
<li><a class="reference internal" href="#installation">Installation</a><ul>
<li><a class="reference internal" href="#geospatial-libraries">Geospatial libraries</a></li>
<li><a class="reference internal" href="#database-installation">Database installation</a></li>
<li><a class="reference internal" href="#add-django-contrib-gis-to-installed-apps">Add <tt class="docutils literal"><span class="pre">django.contrib.gis</span></tt> to <tt class="docutils literal"><span class="pre">INSTALLED_APPS</span></tt></a></li>
<li><a class="reference internal" href="#add-google-projection-to-spatial-ref-sys-table">Add Google projection to <tt class="docutils literal"><span class="pre">spatial_ref_sys</span></tt> table</a></li>
</ul>
</li>
<li><a class="reference internal" href="#troubleshooting">Troubleshooting</a><ul>
<li><a class="reference internal" href="#library-environment-settings">Library environment settings</a><ul>
<li><a class="reference internal" href="#ld-library-path-environment-variable"><tt class="docutils literal"><span class="pre">LD_LIBRARY_PATH</span></tt> environment variable</a></li>
<li><a class="reference internal" href="#setting-system-library-path">Setting system library path</a></li>
<li><a class="reference internal" href="#install-binutils">Install <tt class="docutils literal"><span class="pre">binutils</span></tt></a></li>
</ul>
</li>
</ul>
</li>
<li><a class="reference internal" href="#platform-specific-instructions">Platform-specific instructions</a><ul>
<li><a class="reference internal" href="#mac-os-x">Mac OS X</a><ul>
<li><a class="reference internal" href="#python">Python</a></li>
<li><a class="reference internal" href="#homebrew">Homebrew</a></li>
<li><a class="reference internal" href="#kyngchaos-packages">KyngChaos packages</a><ul>
<li><a class="reference internal" href="#psycopg2">psycopg2</a></li>
</ul>
</li>
<li><a class="reference internal" href="#fink">Fink</a></li>
<li><a class="reference internal" href="#macports">MacPorts</a></li>
</ul>
</li>
<li><a class="reference internal" href="#windows">Windows</a><ul>
<li><a class="reference internal" href="#id20">Python</a></li>
<li><a class="reference internal" href="#postgresql">PostgreSQL</a></li>
<li><a class="reference internal" href="#postgis">PostGIS</a></li>
<li><a class="reference internal" href="#id24">psycopg2</a></li>
<li><a class="reference internal" href="#osgeo4w">OSGeo4W</a></li>
<li><a class="reference internal" href="#modify-windows-environment">Modify Windows environment</a></li>
<li><a class="reference internal" href="#install-django-and-set-up-database">Install Django and set up database</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>

  <h3>Browse</h3>
  <ul>
    
      <li>Prev: <a href="../tutorial.html">GeoDjango Tutorial</a></li>
    
    
      <li>Next: <a href="geolibs.html">Installing Geospatial libraries</a></li>
    
  </ul>
  <h3>You are here:</h3>
  <ul>
      <li>
        <a href="../../../../index.html">Django 1.7.8.dev20150401230226 documentation</a>
        
          <ul><li><a href="../../../index.html">API Reference</a>
        
          <ul><li><a href="../../index.html"><tt class="docutils literal"><span class="pre">contrib</span></tt> packages</a>
        
          <ul><li><a href="../index.html">GeoDjango</a>
        
        <ul><li>GeoDjango Installation</li></ul>
        </li></ul></li></ul></li></ul>
      </li>
  </ul>

  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="../../../../_sources/ref/contrib/gis/install/index.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../../../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
              <h3>Last update:</h3>
              <p class="topless">Apr 02, 2015</p>
          </div>
        
      
    </div>

    <div id="ft">
      <div class="nav">
    &laquo; <a href="../tutorial.html" title="GeoDjango Tutorial">previous</a>
     |
    <a href="../../../index.html" title="API Reference" accesskey="U">up</a>
   |
    <a href="geolibs.html" title="Installing Geospatial libraries">next</a> &raquo;</div>
    </div>
  </div>

      <div class="clearer"></div>
    </div>
  </body>
</html>